import api from '../../utils/api';
import { myRequest } from '../../utils/request';

Page({

    /**
     * 页面的初始数据
     */
    data: {
        collectList: [],
        newList: [],
        listenList: [],
        month: 0,
        day: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getTopFiveCollectList();
        this.getTopFiveNewList();
        this.getTopFiveListenList();
        let now = new Date();
        this.setData({month: now.getMonth() +1, day: now.getDate()});
    },


     // 跳转音乐播放页面
     goToMusicPlayer(event) {
        const data = event.currentTarget.dataset; 
        let music = data.music;
        wx.navigateTo({
          url: '/pages/player/player?music=' + JSON.stringify(music),
        })
    },

     // 获取收藏榜数据
     async getTopFiveCollectList() {
        const res = await myRequest({
            url: '/app/music/topFiveCollect',
            method: 'POST',
            data: {page: 1, size: 5}
        });
        if(res.data.code === 0) {
            let result = res.data.data;
            this.setData({collectList: result});
        }
    },

     // 获取新歌榜数据
     async getTopFiveNewList() {
        const res = await myRequest({
            url: '/app/music/topFiveNew',
            method: 'POST',
            data: {page: 1, size: 5}
        });
        if(res.data.code === 0) {
            let result = res.data.data;
            this.setData({newList: result});
        }
    },


     // 获取热歌榜数据
     async getTopFiveListenList() {
        const res = await myRequest({
            url: '/app/music/topFiveListen',
            method: 'POST',
            data: {page: 1, size: 5}
        });
        if(res.data.code === 0) {
            let result = res.data.data;
            this.setData({listenList: result});
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})